//
//  CTCOfflineConsultRecordsCell.m
//  CTC
//
//  Created by zhangfuwei on 2017/4/17.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "CTCOfflineConsultRecordsCell.h"
#import "CTCOfflineConsultRecordsModel.h"

#import <Masonry.h>
//  视图间距
static CGFloat kMargin     = 10;
static CGFloat kViewMargin = 15;
static CGFloat kEdgeMargin = 20;


@implementation CTCOfflineConsultRecordsCell{
    
    UIImageView *_headImageView; // 头像
    UIView      *_redPoint;// 红点提醒
    UILabel *_nameLabel; // 姓名
    UILabel *_companyLabel;//  公司
    UILabel *_contentLabel; // 内容
    UILabel *_timeLabel; // 时间
    UILabel *_stateLabel; // 接单状态
    
    UIView  *_splitLine; // 分割线
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self loadCustomizedSubviews];
    }
    return self;
}


- (void)loadCustomizedSubviews {
    _headImageView = [[UIImageView alloc] init];
    _headImageView.layer.cornerRadius = 5;
    _headImageView.clipsToBounds = YES;
    
    _redPoint       = [[UIView alloc] init];
    _redPoint.backgroundColor = [UIColor redColor];
    _redPoint.layer.cornerRadius = 5;
    _redPoint.clipsToBounds = YES;
    _redPoint.hidden = YES;

    _nameLabel      = [[UILabel alloc] init];
    _companyLabel   = [[UILabel alloc] init];
    _timeLabel      = [[UILabel alloc] init];
    _stateLabel     = [[UILabel alloc] init];
    _contentLabel   = [[UILabel alloc] init];
    
    _timeLabel.textAlignment        = NSTextAlignmentLeft;
    _stateLabel.textAlignment       = NSTextAlignmentRight;
    
    _contentLabel.numberOfLines     = 0;
    
    
    _nameLabel.font     = SYSTEMFONT(15);
    _companyLabel.font  = SYSTEMFONT(12);
    _contentLabel.font  = SYSTEMFONT(14);
    _timeLabel.font     = SYSTEMFONT(12);
    _stateLabel.font    = SYSTEMFONT(13);
    
    
    _nameLabel.textColor        = HEXCOLOR(0x4c5c6c);
    _companyLabel.textColor     = HEXCOLOR(0x666666);
    _contentLabel.textColor     = HEXCOLOR(0x333333);
    _timeLabel.textColor        = HEXCOLOR(0xb7b7b7);
    
    _splitLine = [[UIView alloc] init];
    _splitLine.backgroundColor = HEXCOLOR(0xeeedee);
    
    [self.contentView addSubview:_headImageView];
    [self.contentView insertSubview:_redPoint aboveSubview:_headImageView];
    
    [self.contentView addSubview:_nameLabel];
    [self.contentView addSubview:_companyLabel];
    [self.contentView addSubview:_contentLabel];
    [self.contentView addSubview:_timeLabel];
    [self.contentView addSubview:_stateLabel];
    
    [self.contentView addSubview:_splitLine];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    _headImageView.frame = CGRectMake(kViewMargin, kMargin, 50, 50);
    _redPoint.frame = CGRectMake(kViewMargin+40, kMargin, 10, 10);

    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headImageView.mas_right).offset(kViewMargin);
        make.top.equalTo(self.contentView).offset(13);
        make.height.equalTo(@(15));
    }];

    
    [_companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@12);
        make.left.equalTo(_nameLabel);
        make.top.equalTo(_nameLabel.mas_bottom).offset(kViewMargin);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(kEdgeMargin);
        make.top.equalTo(_companyLabel.mas_bottom).offset(17);
        make.right.equalTo(self.contentView).offset(-1*kEdgeMargin);
        
    }];
    
    [_splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(kViewMargin);
        make.right.equalTo(self.contentView).offset(-1*kEdgeMargin);
        make.top.equalTo(_contentLabel.mas_bottom).offset(1*kViewMargin);
        make.height.equalTo(@0.5);
//        make.bottom.equalTo(self.contentView).offset(-1*30);
    }];
    
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_splitLine);
        make.top.equalTo(_splitLine.mas_bottom).offset(kMargin);
        make.height.equalTo(@12);
        make.bottom.equalTo(self.contentView).offset(-1*12);
    }];
    
    [_stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-1*kViewMargin);
//        make.top.equalTo(_splitLine.mas_bottom);
        make.centerY.equalTo(_timeLabel);
        make.height.equalTo(@13);
//        make.bottom.equalTo(self.contentView);
    }];
    
}


- (void)setDataModel:(CTCOfflineConsultRecordsDataModel *)dataModel {
    _dataModel = dataModel;
    NSString *state = @"未接单";
    UIColor *stateColor ;
    switch (dataModel.status.intValue) {
        case 0:
            state = @"未接单";
            stateColor = HEXCOLOR(0xfb6a31);
            break;
        case 1:
            state = @"已接单";
            stateColor = HEXCOLOR(0x00c44e);
            break;
        case 2:
            state = @"已拒单";
            stateColor = COLOR_NAVBAR_BLUE;
            break;
        case 3:
            state = @"服务完成";
            stateColor = HEXCOLOR(0xffa200);
            break;
        case 4:
            state = @"服务无响应";
            stateColor = HEXCOLOR(0xcc100f);
            break;
        default:
            break;
    }
    _redPoint.hidden = dataModel.status.intValue;
    [SDWebImageTool imageView:_headImageView imageName:dataModel.headImg placeHolder:@"default-head" showProgress:NO];
    _nameLabel.text         = dataModel.bname;
    _companyLabel.text      = dataModel.companyName;
    _contentLabel.text      = dataModel.content;
    _timeLabel.text         = [NSDate stringFromTimestamp:dataModel.updateTime dateFormat:@"yyyy-MM-dd HH:mm"];
    _stateLabel.text        =  state;
    _stateLabel.textColor   =  stateColor;
    
    [self layoutIfNeeded];
}

@end
